import {sessionIDByRoleID} from "@/api/ai_role_api";
import {Message} from "@arco-design/web-vue";
import {sessionCreateApi} from "@/api/session_list_api";
import router from "@/router";
import {userStorei} from "@/stores/user_store";
import {showLogin} from "@/components/web/f_login";

export async function getSessionIDByRoleID(roleID: number) {
    const store = userStorei()
    if (!store.isLogin){
        Message.warning("需要登陆")
        showLogin()
        return
    }

    const res = await sessionIDByRoleID(roleID)
    if (res.code) {
        Message.error(res.msg)
        return
    }
    let sessionID = res.data
    if (res.data === 0) {
        const res1 = await sessionCreateApi(roleID)
        if (res1.code) {
            Message.error(res.msg)
            return
        }
        sessionID = res1.data
    }
    router.push({name: "chat", params: {id: sessionID}})
}